import store from '@/store'

export default {
  inserted(el, binding, vnode) {
    const { value } = binding
    const permissionCodes = store.getters.permissionCodes
    if (value) {
      const permissionCode = value

      const hasPermission = ()=>{
        return permissionCodes.includes(permissionCode)
      }

      if (!hasPermission()) {
        el.parentNode && el.parentNode.removeChild(el)
      }
    } else {
      throw new Error(`need permissionCode! Like v-permissionCode="person:manager:add"`)
    }
  }
}
